import pandas as pd

from fgtj.statistics import sum_percent, count_percent,merge

# excel的地址
file_path = rf''
# excel的sheet_name
sheet_name = '主表'
# excel的索引（不能重复的都能做索引）
index_col='项目名称（勿修改）'
# excel的表头 如果是1就是从第2行开始
header = 1
# 分组字段
groupby_cols = ['市州','领域一级']
# 统计字段
statistics_cols = ['总投资','剩余投资','年度投资（万）']

# 新文件名称
new_file_name = '市州领域一级汇总'


df = pd.read_excel(io=file_path, sheet_name= sheet_name, index_col=index_col,header=1)
groupbys=[]
count = count_percent(df=df, groupby_cols=groupby_cols)
for col in statistics_cols:
    sum = sum_percent(df=df,ratio=10000,col=col,groupby_cols=groupby_cols)
    groupbys.append(sum)
groupbys.append(count)
df_merge = merge(groupbys)
df_merge.to_excel(rf'D:\Desktop\统计\{new_file_name}.xlsx',sheet_name=new_file_name)